package com.slipper.sfts.order.service.support;

import com.slipper.PaasContext;
import com.slipper.qmt.vo.CancelErrorVO;
import com.slipper.sfts.api.stock.bo.StockOrderBO;
import com.slipper.sfts.order.service.IDealer;
import com.slipper.sfts.stock.service.StockOrderMessageService;
import com.slipper.sfts.stock.service.StockOrderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class CancelErrorDealer implements IDealer<CancelErrorVO> {
    private static final Logger logger = LoggerFactory.getLogger(CancelErrorDealer.class);

    @Override
    public void doDeal(CancelErrorVO vo) {
        logger.info("接收到撤单出错回调消息：{}", vo);

        StockOrderService stockOrderService = PaasContext.getBean(StockOrderService.class);
        StockOrderBO stockOrder = stockOrderService.queryByOrderSysId(vo.getOrderSysId());
        if (stockOrder != null) {
            String message = "[" + stockOrder.getCode() + "]撤单出错，" +
                    "出错信息[" + vo.getErrorMsg() + "]";
            PaasContext.getBean(StockOrderMessageService.class).save(
                    stockOrder.getMemberId(), stockOrder.getAccountId(), message);
        }
    }
}
